package com.gzdh.dishrecognition.util;


import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

/**
 * @ProjectName: 团餐
 * @ClassName: DateUtil
 * @Description: 日期工具类
 * @Author: bd-001935
 * @CreateDate: 4/17/22 8:42 PM
 * @UpdateUser: bd-001935
 * @UpdateDate: 4/17/22 8:42 PM
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
public class DateUtil {

    public static String getSystemTime() {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm");
        Date date = new Date(System.currentTimeMillis());//获取系统时间
        return simpleDateFormat.format(date);
    }

    public static String getCurrentDate() {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        format.setTimeZone(TimeZone.getTimeZone("GMT+08")); //设置时区
        Date curDate = new Date(System.currentTimeMillis()); //获取当前时间
        String dateStr = format.format(curDate);   //格式转换
        return dateStr;
    }

    public static String getCurrentDateNoLine() {
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
        format.setTimeZone(TimeZone.getTimeZone("GMT+08")); //设置时区
        Date curDate = new Date(System.currentTimeMillis()); //获取当前时间
        String dateStr = format.format(curDate);   //格式转换
        return dateStr;
    }

    public static String getCurrentDateTime() {
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
        format.setTimeZone(TimeZone.getTimeZone("GMT+08")); //设置时区
        Date curDate = new Date(System.currentTimeMillis()); //获取当前时间
        String dateStr = format.format(curDate);   //格式转换
        return dateStr;
    }

    public static String getCurrentDateTimeNormal() {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        format.setTimeZone(TimeZone.getTimeZone("GMT+08")); //设置时区
        Date curDate = new Date(System.currentTimeMillis()); //获取当前时间
        String dateStr = format.format(curDate);   //格式转换
        return dateStr;
    }

//    public static String formatTime(String original) {
//        if (!StringUtils.isEmpty(original)) {
//            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//            try {
//                Date date = simpleDateFormat.parse(original);
//                SimpleDateFormat newSf = new SimpleDateFormat("MM-dd HH:mm");
//                return newSf.format(date);
//            } catch (ParseException e) {
//                e.printStackTrace();
//                return "";
//            }
//        }
//        return "";
//    }
//
//    public static String formatTimeNoLine(String original) {
//        if (!StringUtils.isEmpty(original)) {
//            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
//            try {
//                Date date = simpleDateFormat.parse(original);
//                SimpleDateFormat newSf = new SimpleDateFormat("MM-dd HH:mm");
//                return newSf.format(date);
//            } catch (ParseException e) {
//                e.printStackTrace();
//                return "";
//            }
//        }
//        return "";
//    }
//
//    public static long formatTimeMillis(String original) {
//        if (!StringUtils.isEmpty(original)) {
//            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
//            try {
//                Date date = simpleDateFormat.parse(original);
//                return date.getTime();
//            } catch (ParseException e) {
//                e.printStackTrace();
//            }
//        }
//        return System.currentTimeMillis();
//    }

    /**
     * 获得某天的过去/未来几天
     *
     * @param oneday
     * @param amount
     * @return
     */
    public static Date daysAgoOrAfter(Date oneday, int amount) {
        Calendar mon = Calendar.getInstance();
        mon.setTime(oneday);
        mon.add(Calendar.DATE, amount);
        return mon.getTime();
    }

    /**
     *
     * @param nowDate   要比较的时间
     * @param startDate   开始时间
     * @param endDate   结束时间
     * @return   true在时间段内，false不在时间段内
     * @throws Exception
     */
    public static boolean hourMinuteBetween(String nowDate, String startDate, String endDate) throws Exception{

        SimpleDateFormat format = new SimpleDateFormat("HH:mm");

        Date now = format.parse(nowDate);
        Date start = format.parse(startDate);
        Date end = format.parse(endDate);

        long nowTime = now.getTime();
        long startTime = start.getTime();
        long endTime = end.getTime();

        return nowTime >= startTime && nowTime <= endTime;
    }
}
